<?php
    class resize
    {
        function resize_img($width, $height, $resizeLocation, $originalLocation, $scale = 0, $type = 'resize') {
            $extension = strtolower(substr(basename($resizeLocation), strrpos(basename($resizeLocation), ".") + 1));
            
            $quality = 75;
            // -- get some information about the file
            list($originalWidth,$originalHeight) = getimagesize($originalLocation);
                
            switch (strtolower($extension)) {
                case 'gif': $srcImg = imagecreatefromgif($originalLocation); 
                    break;
                case 'jpg': $srcImg = imagecreatefromjpeg($originalLocation); 
                    break;
                case 'jpeg': $srcImg = imagecreatefromjpeg($originalLocation); 
                    break;
                case 'png': $srcImg = imagecreatefrompng($originalLocation); $quality = 9;
                    break;
            }

            $dstImg = imagecreatetruecolor($width, $height);
            imagecopyresampled($dstImg, $srcImg, 0, 0 , 0, 0, $width, $height, $originalWidth, $originalHeight);
            // -- try to write
            switch (strtolower($extension)) {
                case 'jpg':
                    $write = imagejpeg($dstImg, $resizeLocation, $quality);
                    break;
                case 'jpeg':
                    $write = imagejpeg($dstImg, $resizeLocation, $quality);
                    break;
                case 'png':
                    $write = imagepng($dstImg, $resizeLocation, $quality);
                    break;
                case 'gif':
                    $write = imagegif($dstImg, $resizeLocation, $quality);
                    break;
            }
            chmod($resizeLocation, 0777);
            imagedestroy($dstImg);
            return $write;
        }
    }

?>		